package com.icbc.open.chengdu.demo.account.scode;

import com.csii.pp.icbc.util.Util;
import com.icbc.api.DefaultIcbcClient;
import com.icbc.api.internal.util.internal.util.fastjson.JSON;
import com.icbc.api.request.SettlementAccountSCodeVerifyRequestV1;
import com.icbc.api.response.SettlementAccountSCodeVerifyResponseV1;
import com.icbc.open.chengdu.demo.BaseData;
import com.icbc.open.chengdu.demo.utils.SaveFileUtils;
import com.icbc.open.chengdu.demo.utils.SecretUtils;

/**
 * 验证码校验
 *
 * @author xcz
 */
public class SettlementAccountSCodeVerifyTest {


    public static void main(String[] args) throws Exception {
        DefaultIcbcClient client = new DefaultIcbcClient(BaseData.APP_ID, BaseData.MY_RSA_PRIVATE_KEY, BaseData.ICBC_RSA_PUBLIC_KEY);
        SettlementAccountSCodeVerifyRequestV1 request = new SettlementAccountSCodeVerifyRequestV1();
        SettlementAccountSCodeVerifyRequestV1.SettlementAccountSCodeVerifyRequestV1Biz bizContent = new SettlementAccountSCodeVerifyRequestV1.SettlementAccountSCodeVerifyRequestV1Biz();
		request.setServiceUrl(BaseData.ACCOUNT_SCODE_VERIFY_URL);//API地址
		bizContent.setCorpDate(BaseData.TEST_CORP_DATE);//合作方工作日期
		bizContent.setCorpNo(BaseData.APP_ID);//合作方机构编号
		bizContent.setCorpSerno(Util.getNonceStr(16));//合作方交易单号
		//bizContent.setCorpSernoOriginal(SaveFileUtils.getOpenAccount());//原合作方交易单号 开户
		//bizContent.setCorpSernoOriginal(SaveFileUtils.getCloseAccount());//原合作方交易单号 销户
		bizContent.setCorpSernoOriginal(SaveFileUtils.getBindMedium());//原合作方交易单号 绑定
		bizContent.setOutServiceCode("1");//外部服务代码
		bizContent.setTrxAccDate(BaseData.TEST_TRX_ACC_DATE);//合作方交易日期
		bizContent.setTrxAccTime(BaseData.TEST_TRX_ACC_TIME);//合作方交易时间
		bizContent.setSmsSCode("955888");//短信验证码 测试3环境默认为955888
		bizContent.setSmsSendNo(SaveFileUtils.getSmsSendNo());//短信验证码编号
		request.setBizContent(bizContent);
        SettlementAccountSCodeVerifyResponseV1 response = client.execute(request);
		System.out.println(JSON.toJSONString(response));
		if (response.isSuccess() && response.getReturnCode() == 0) {
			//成功
			System.out.println("II类卡号：" + SecretUtils.decryptMediumId(response.getMediumId(), response.getSecretKey()));
		} else {
			//失败
		}

    }
}
